/* ****************************************************************
*		Breaking Point: Mod
******************************************************************* 
* 	Breaking Point: Tournaments
*	Website: www.bptourneys.com
*
*	Mod Authors:	Blyk, Fiddy, Hellfire
*   Original Mod: 	Fiddy
*	
******************************************************************** */
/* Called on Map Load Of main() in Gametype */
main()
{
	level.setdvar = maps\mp\gametypes\_utlty::set_dvar;
	
	// Allies Side Selector
	level.allies_teamsetting = [[level.setdvar]]("bp_allies", "default");
	
	// Axis Skin Selector
	level.axis_skin_teamsetting = [[level.setdvar]]("bp_axis", "default");

	// Setup FPS
	level.fps = getCvarInt("sv_fps");
	switch(level.fps) 
	{
		case 30:
			level.fps_multiplier = 1.51382;
			level.frame = .033;
			break;
		case 25:
			level.fps_multiplier = 1.26110;
			level.frame = .039;
			break;
		case 20:
		default:
			level.fps = setcvar("sv_fps", 20);
			level.fps_multiplier = 1.0;
			level.frame = .05;
			break;
	}
	
	precacheShader("hud_autodl");
	
	// Set Round Based Attacker Counters
	if(!isDefined(game["allied_attack_count"]))
		game["allied_attack_count"] = 0;
	if(!isDefined(game["axis_attack_count"]))
		game["axis_attack_count"] = 0;
	if(!isDefined(game["roundwinner"]))
		game["roundwinner"] = getcvar("bp_mapdefenders");
	if(!isDefined(game["mode"]))
		game["mode"] = getcvar("bp_matchmode");
	if(!isDefined(game["live"]))
		game["live"] = false; //[[level.setdvar]]("bp_live", 0, 0, 1);;
	if(!isDefined(game["start_delay"]))
		game["start_delay"] = [[level.setdvar]]("bp_golive_delay", 70, 1, 120);
	
	
	if(game["mode"] != "battle")
		game["mode"] = "pub";
		

	// Tactical CTF
	level.tacticalCTF = [[level.setdvar]]("bp_tacticalCTF", 0, 0, 1);
	
	// Ambient Variables
	game["ambient_fx"] = [[level.setdvar]]("bp_allow_ambientfx", 1, 0, 1);
	game["ambient_bg"] = [[level.setdvar]]("bp_allow_ambientbg", 1, 0, 1);
	game["ambient_bg_override"]	= [[level.setdvar]]("bp_ambientbg_override", 1, 0, 1);
	game["ambient_bg_sound"] = isAcceptableAmbient(getcvar("bp_ambientbg_sound"));
	
}

/* ******************************************************************************
*	MAP SETUP
******************************************************************************* */ 

/* Called Once Before the Match Begins in Start Gametype */
map_setup()
{
	// Remove Weapons
	weaponlist = maps\mp\gametypes\_utlty::get_weaponlist();
    maps\mp\gametypes\_bpmod_setup::remove_weapons(weaponlist);

    // Remove Fog
	setExpFog(0.0000000000000001,0.0000000000000001,0,0,0);
    setCullFog(100000,1000000, 0,0,0,0);

	// Set Allied Side
	switch(level.allies_teamsetting) {
		case "american":
			game["allies"] = "american"; 	break;
		case "british":
			game["allies"] = "british"; 	break;
		case "russian":
			game["allies"] = "russian";		break;
	}
	
	// Set Axis Skin
	switch(level.axis_skin_teamsetting) {
		case "western":
			game["german_soldiertype"] = "normandy"; 	break;
		case "eastern":
			game["german_soldiertype"] = "winterlight"; 	break;
		case "africa":
			game["german_soldiertype"] = "africa";		break;
	}
	
    // More Side Settings
    game["axis"] = "german";
    game["attackers"] = "allies";
    game["defenders"] = "axis";
	
    // Set Up Bloom and Sky Bleeding Effects
    setCvar("r_glowbloomintensity0", ".25");
    setCvar("r_glowbloomintensity1", ".25");
    setcvar("r_glowskybleedintensity0",".3");
	
	// [BP] Turn Off Ambient
	if(isDefined(game["ambient_bg"]) && game["ambient_bg"] != true)
	{
		ambientStop();
		musicStop();
	}
	if(isDefined(game["ambient_bg_override"]) && game["ambient_bg_override"])
	{
		ambientStop();
		musicStop();
		
		ambientPlay(game["ambient_bg_sound"]);
	}
}

override_mapfx() 
{
	// Precache & Override Default Map FX file
	level._effect["flak_explosion"]	= loadfx("fx/explosions/flak88_explosion.efx");
}

/* ******************************************************************************
*	UTILITIES
******************************************************************************* */ 
remove_weapons(weaponlist) 
{
	for (i = 0; i < weaponlist.size; i++) 
	{
		wep_rem = getentarray(weaponlist[i], "classname"); //loads all the weapon placements, if any
		if (wep_rem.size > 0) //checks for existance of specific weapon
		{
			for(j = 0; j < wep_rem.size; j++) 
				wep_rem[j] delete(); //deletes all instances of the weapon
		}
	}
}

remove_mapentity() 
{
	level.allow_turrets = [[level.setdvar]]("bp_allow_turrets", 1, 0, 1);
	
	if (!level.allow_turrets) {
		delete_entity("misc_turret");
		delete_entity("misc_mg42");
	}
}

delete_entity(entity)
{
	entities = getentarray(entity, "classname");
	for(i = 0; i < entities.size; i++)
		entities[i] delete();
}

isAcceptableAmbient(ambientsound)
{
	isAcceptable = false;
	
	switch(ambientsound)
	{
		case "ambient_france":	
		case "ambient_africa":
		case "ambient_russia":
			isAcceptable = true;
			break;
		default:
			isAcceptable = false;
	}
	
	if(!isAcceptable)
		ambientsound = "ambient_france";
	
	return ambientsound;
}